/**
 * Created by wanthering on 2017/8/16.
 */

const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const AudioSchema = new mongoose.Schema({
  id: Number,
  qun: String,
  url: String,
  title: String,
  desc: String,
  faceUrl: String,
  info:String,
  qunUrl: String,
  admin: String,
  posterUrl: String,
  meta:{
    createAt:{type:Date,default:Date.now()},
    updateAt:{type:Date,default:Date.now()}
  }
});

AudioSchema.pre('save',function(next){
  if(this.isNew){
    this.meta.createAt = this.meta.updateAt = Date.now();
  }else{
    this.meta.updateAt = Date.now();
  }
  next();
});

module.exports = mongoose.model('Audio',AudioSchema);